import os
import pygame
import random

# 工具类
class Utils:
    name = "123"
    # def __init__(self):
    #     pass
    '''
        # 加载背景图片
         file:文件名
        size:图片大小
        main_dir：主文件路径
    '''
    def load_image(file,size,main_dir):
        """loads an image, prepares it for play"""
        file = os.path.join(main_dir, "data", file)
        try:
            surface = pygame.image.load(file)
            surface = pygame.transform.scale(surface, size)
        except pygame.error:
            raise SystemExit(f'Could not load image "{file}" {pygame.get_error()}')
        return surface.convert()


    # 加载音频
    def load_sound(file,main_dir):
        """because pygame can be compiled without mixer."""
        if not pygame.mixer:
            return None
        file = os.path.join(main_dir, "data", file)
        try:
            sound = pygame.mixer.Sound(file)
            return sound
        except pygame.error:
            print(f"Warning, unable to load, {file}")
        return None

    # 获取随机数字+大小写字母
    def getRandom(exclude_nums):
        nums = [i for i in range(48,58) if i not in exclude_nums]
        nums_a_z = [i for i in range(97,123) if i not in exclude_nums]
        nums_A_Z = [i for i in range(65,91) if i not in exclude_nums]
        nums.extend(nums_a_z)
        nums.extend(nums_A_Z)
        random_num = 1
        if len(nums)>0:
            random_num = random.choice(nums)
            exclude_nums.append(random_num)
        return random_num
